package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlUserInfoField entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlUserInfoField
 * @author MyEclipse Persistence Tools
 */

public class MdlUserInfoFieldDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlUserInfoFieldDAO.class);
	// property constants
	public static final String SHORTNAME = "shortname";
	public static final String NAME = "name";
	public static final String DATATYPE = "datatype";
	public static final String DESCRIPTION = "description";
	public static final String DESCRIPTIONFORMAT = "descriptionformat";
	public static final String CATEGORYID = "categoryid";
	public static final String SORTORDER = "sortorder";
	public static final String REQUIRED = "required";
	public static final String LOCKED = "locked";
	public static final String VISIBLE = "visible";
	public static final String FORCEUNIQUE = "forceunique";
	public static final String SIGNUP = "signup";
	public static final String DEFAULTDATA = "defaultdata";
	public static final String DEFAULTDATAFORMAT = "defaultdataformat";
	public static final String PARAM1 = "param1";
	public static final String PARAM2 = "param2";
	public static final String PARAM3 = "param3";
	public static final String PARAM4 = "param4";
	public static final String PARAM5 = "param5";

	public void save(MdlUserInfoField transientInstance) {
		log.debug("saving MdlUserInfoField instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlUserInfoField persistentInstance) {
		log.debug("deleting MdlUserInfoField instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlUserInfoField findById(java.lang.Long id) {
		log.debug("getting MdlUserInfoField instance with id: " + id);
		try {
			MdlUserInfoField instance = (MdlUserInfoField) getSession().get(
					"idv.loveloser.dao.MdlUserInfoField", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlUserInfoField instance) {
		log.debug("finding MdlUserInfoField instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlUserInfoField")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlUserInfoField instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlUserInfoField as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByShortname(Object shortname) {
		return findByProperty(SHORTNAME, shortname);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByDatatype(Object datatype) {
		return findByProperty(DATATYPE, datatype);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByDescriptionformat(Object descriptionformat) {
		return findByProperty(DESCRIPTIONFORMAT, descriptionformat);
	}

	public List findByCategoryid(Object categoryid) {
		return findByProperty(CATEGORYID, categoryid);
	}

	public List findBySortorder(Object sortorder) {
		return findByProperty(SORTORDER, sortorder);
	}

	public List findByRequired(Object required) {
		return findByProperty(REQUIRED, required);
	}

	public List findByLocked(Object locked) {
		return findByProperty(LOCKED, locked);
	}

	public List findByVisible(Object visible) {
		return findByProperty(VISIBLE, visible);
	}

	public List findByForceunique(Object forceunique) {
		return findByProperty(FORCEUNIQUE, forceunique);
	}

	public List findBySignup(Object signup) {
		return findByProperty(SIGNUP, signup);
	}

	public List findByDefaultdata(Object defaultdata) {
		return findByProperty(DEFAULTDATA, defaultdata);
	}

	public List findByDefaultdataformat(Object defaultdataformat) {
		return findByProperty(DEFAULTDATAFORMAT, defaultdataformat);
	}

	public List findByParam1(Object param1) {
		return findByProperty(PARAM1, param1);
	}

	public List findByParam2(Object param2) {
		return findByProperty(PARAM2, param2);
	}

	public List findByParam3(Object param3) {
		return findByProperty(PARAM3, param3);
	}

	public List findByParam4(Object param4) {
		return findByProperty(PARAM4, param4);
	}

	public List findByParam5(Object param5) {
		return findByProperty(PARAM5, param5);
	}

	public List findAll() {
		log.debug("finding all MdlUserInfoField instances");
		try {
			String queryString = "from MdlUserInfoField";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlUserInfoField merge(MdlUserInfoField detachedInstance) {
		log.debug("merging MdlUserInfoField instance");
		try {
			MdlUserInfoField result = (MdlUserInfoField) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlUserInfoField instance) {
		log.debug("attaching dirty MdlUserInfoField instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlUserInfoField instance) {
		log.debug("attaching clean MdlUserInfoField instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}